# -*- coding: utf-8 -*-

# 
# this is plugin example for driver install, 
#
# Created: Thu Apr 21 12:50:32 2011
#      
#  
#  date             author          issues
#  2011-Apr-21   Wan            creator
#
#
#



import os, sys, unittest,  imp,  fnmatch,  pdb

class   di(unittest.TestCase):
    ui = None
    
    def setUI(self,  ui = None):
        di.ui = ui
        
    def setUp(self):
        if di.ui == None:
            raise RuntimeError
        di.ui.printLog("*************** test case begin **************")
        
    def tearDown(self):
        di.ui.printLog("**************** test case end *********************")
            
    def test_init(self):
        """
        analyze the configure file,  it's called by framework, mandotory!!!
        """
        di.ui.printLog("we are testing driver install plugin->[init]")
        di.ui.printLog("%s - %s"%(__file__, sys._getframe().f_code.co_name ))       
        di.ui.printLog("we did driver install plugin test!")
        
    def test_run(self):
        """
        running logic for plugin, it's called by framwork, mandotory!!!
        """
        di.ui.printLog("we are testing driver install plugin->[run]")
        di.ui.printLog("%s - %s"%(__file__, sys._getframe().f_code.co_name ))    
        
        
    def test_infcheck (self):
        di.ui.printLog("DRIVERINSTALLERSTART")
        inflist = []
        workdir = []
        novatelinfs = []
        finalworkdir = []
        for path, names, files in os.walk("c:\\program files"):
                for name in files:
                        if fnmatch.fnmatch(name,'*.inf'):
                                inflist.append(name)
                                workdir.append(path)

        index = 0
        totalinf = len(inflist)


        while index < totalinf:
                os.chdir(workdir[index])
                readfile = open(inflist[index],encoding='utf-8',errors='ignore')
                for line in readfile:
                        if "Novatel" in line and inflist[index] not in novatelinfs:
                                novatelinfs.append(inflist[index])
                                finalworkdir.append(workdir[index])
                index = index + 1

        index = 0
        totalinf = len(novatelinfs)

        while index < totalinf:
                os.chdir(finalworkdir[index])
                readfile = open(novatelinfs[index],encoding='utf-8',errors='ignore')
                for line in readfile:
                       if "DriverVer" in line:
                                #pdb.set_trace()
                                di.ui.printLog(finalworkdir[index].strip("\n"))
                                
                                di.ui.printLog(str(novatelinfs[index]) + "\n" + str(line.strip("\n")))
                                index = index + 1
                                
    def test_installDriver(self):
        """
        install driver is the verification item for driver install, sometime it will run with params
        """
        di.ui.printLog("we are testing driver install plugin->[install driver]")
        di.ui.printLog("%s - %s"%(__file__, sys._getframe().f_code.co_name ))  
        di.ui.printLog("we did driver install plugin test!")  
        
    def test_uninstallDriver(self):
        """
        uninstall driver is the verification item for driver install sometime it will run with params
        """
        di.ui.printLog("we are testing driver install plugin->[uninstall driver]")
        di.ui.printLog("%s - %s"%(__file__, sys._getframe().f_code.co_name ))  
        di.ui.printLog("we did driver install plugin test!")  
        
    def test_regCheck(self):
        """
        """
        di.ui.printLog("we are testing driver install plugin->[reg check]")
        di.ui.printLog("%s - %s"%(__file__, sys._getframe().f_code.co_name )) 
        di.ui.printLog("we did driver install plugin test!")   

if __name__ == "__main__":
    unittest.main()
